<?php

namespace app\api\controller;

class CaptchaApi extends Base
{
    public $name = 'CaptchaApi';

    /**
     * 获取验证码
     * @return void
     * @throws \Throwable
     */
    public function clickCaptcha()
    {
        try{
            $id      = input("param.id");
            $captcha = new \app\common\lib\CaptchaLib\ClickCaptcha();
            $result = $captcha->creat($id);
            if($result){
                return returnResult(config("config.code.success"),config("config.describe.success"),$result);
            }else{
                return returnResult(config("config.code.error"),config("config.describe.captcha.invalid"));
            }
        }catch (\Exception $e){
            exception($e,$this->name.'.getCaptcha');
        }
    }

    public function checkClickCaptcha()
    {
        $id      = input("param.id");
        $info      = input("param.info");
        $unset   = input("param.unset")?input("param.unset"):false;
        $captchaObj = new \app\common\lib\CaptchaLib\ClickCaptcha();
        $result = $captchaObj->check($id, $info,$unset);
        if($result){
            return returnResult(config("config.code.success"),config("config.describe.success"),$result);
        }else{
            return returnResult(config("config.code.error"),config("config.describe.captcha.invalid"));
        }
    }

    public function validateCaptcha(){

    }
}